home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 220 / 220.xpi / chrome / flashgot.jar / content / flashgot / DOM.js < prev    next >
Encoding:
JavaScript  |  2010-01-24  |  3.7 KB  |  109 lines

  1. /***** BEGIN LICENSE BLOCK *****
  2.  
  3.     FlashGot - a Firefox extension for external download managers integration
  4.     Copyright (C) 2004-2009 Giorgio Maone - g.maone@informaction.com
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.                              
  20. ***** END LICENSE BLOCK *****/
  21.  
  22. var DOM = {
  23.   getDocShellFromWindow: function(window) {
  24.     try {
  25.       return window.QueryInterface(CI.nsIInterfaceRequestor)
  26.                    .getInterface(CI.nsIWebNavigation)
  27.                    .QueryInterface(CI.nsIDocShell);
  28.     } catch(e) {
  29.       return null;
  30.     }
  31.   },
  32.   getChromeWindow: function(window) {
  33.     try {
  34.       return this.getDocShellFromWindow(window)
  35.         .QueryInterface(CI.nsIDocShellTreeItem).rootTreeItem
  36.         .QueryInterface(CI.nsIInterfaceRequestor)
  37.         .getInterface(CI.nsIDOMWindow).top;
  38.     } catch(e) {
  39.       return null;
  40.     }
  41.   },
  42.   updateStyleSheet: function(sheet, enabled) {
  43.     
  44.     const sssClass = CC["@mozilla.org/content/style-sheet-service;1"];
  45.     if (!sssClass) return;
  46.       
  47.     const sss = sssClass.getService(CI.nsIStyleSheetService);
  48.     const uri = IOS.newURI("data:text/css," + sheet, null, null);
  49.     if (sss.sheetRegistered(uri, sss.USER_SHEET)) {
  50.       if (!enabled) sss.unregisterSheet(uri, sss.USER_SHEET);
  51.     } else {
  52.       try {
  53.         if (enabled) sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
  54.       } catch(e) {
  55.         dump("Error registering stylesheet " + uri + ": " + e + "\n"); 
  56.       }
  57.     }
  58.   },
  59.   
  60.   get windowMediator() {
  61.     delete this.windowMediator;
  62.     return this.windowMediator = CC['@mozilla.org/appshell/window-mediator;1']
  63.                   .getService(CI.nsIWindowMediator);
  64.   },
  65.   
  66.   _winType: null,
  67.   perWinType: function(delegate) {
  68.     var wm = this.windowMediator;
  69.     var w = null;
  70.     var aa = Array.prototype.slice.call(arguments);
  71.     for each(var type in ['navigator:browser', 'emusic:window', 'Songbird:Main']) {
  72.      aa[0] = type;
  73.       w = delegate.apply(wm, aa);
  74.       if (w) {
  75.         this._winType = type;
  76.         break;
  77.       }
  78.     }
  79.     return w;
  80.   },
  81.   get mostRecentBrowserWindow() {
  82.     var res = this._winType && this.windowMediator.getMostRecentWindow(this._winType, true);
  83.     return res || this.perWinType(this.windowMediator.getMostRecentWindow, true);
  84.   },
  85.   get windowEnumerator() {
  86.     var res = this._winType && this.windowMediator.getZOrderDOMWindowEnumerator(this._winType, true);
  87.     return res || this.perWinType(this.windowMediator.getZOrderDOMWindowEnumerator, true);
  88.   },
  89.   
  90.   findChannelWindow: function(channel) {
  91.     for each(var cb in [channel.notificationCallbacks,
  92.                        channel.loadGroup && channel.loadGroup.notificationCallbacks]) {
  93.       if (cb instanceof CI.nsIInterfaceRequestor) {
  94.  
  95.         if (CI.nsILoadContext) try {
  96.         // For Gecko 1.9.1
  97.           return cb.getInterface(CI.nsILoadContext).associatedWindow;
  98.         } catch(e) {}
  99.         
  100.         try {
  101.           // For Gecko 1.9.0
  102.           return cb.getInterface(CI.nsIDOMWindow);
  103.         } catch(e) {}
  104.       }
  105.     }
  106.     return null;
  107.   }
  108.   
  109. };